home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_m_p / mews11.zip / MSWDRV.C < prev    next >
C/C++ Source or Header  |  1992-07-23  |  22KB  |  688 lines

  1. /* The routines in this file provide drivers for display and input under
  2.    the Microsoft Windows environment on an IBM-PC or compatible
  3.    computer.
  4.  
  5.    Must be compiled with Borland C++ 2.0 or MSC 6.0 or later versions.
  6.  
  7.    It should not be compiled if the WINDOW_MSWIN symbol is not set */
  8.  
  9. #define termdef 1           /* don't define term external */
  10.  
  11. #include    "estruct.h"
  12. #include    "elang.h"
  13. #include    <stdio.h>
  14. #include    <time.h>
  15. #include    "eproto.h"
  16. #include    "edef.h"
  17.  
  18. #include    "mswin.h"
  19.  
  20. #define     NPAUSE  1000    /* pause for fence-showing, 1 second */
  21. #define     MARGIN  8       /* size of minimal margin and */
  22. #define     SCRSIZ  20      /* scroll size for extended lines */
  23.  
  24. /* terminal interface table entries */
  25.  
  26. static int   PASCAL mswnop();
  27. static int   PASCAL mswopen();
  28. static int   PASCAL mswgetc();
  29. static int   PASCAL mswputc();
  30. static int   PASCAL mswflush();
  31. static int   PASCAL mswbeep();
  32. static int   PASCAL mswmove();
  33. static int   PASCAL msweeol();
  34. static int   PASCAL msweeop();
  35. static int   PASCAL mswbeep();
  36. static int   PASCAL mswrev();
  37. static int   PASCAL mswrez();
  38. #if COLOR
  39. static int   PASCAL mswsetfor();
  40. static int   PASCAL mswsetback();
  41. #endif
  42. static int   PASCAL mswsleep();
  43. static int   PASCAL mswnewscr();
  44. static int   PASCAL mswdelscr();
  45. static int   PASCAL mswselscr();
  46. static int   PASCAL mswsizscr();
  47. static int   PASCAL mswtopscr();
  48.  
  49. /* Standard terminal interface dispatch table.
  50. */
  51. NOSHARE TERM term    = {
  52.         HUGE,
  53.         HUGE,
  54.         HUGE,
  55.         HUGE,
  56.         0,
  57.         0,
  58.     MARGIN,
  59.     SCRSIZ,
  60.     NPAUSE,
  61.         mswopen,    /* t_open: Open terminal at the start */
  62.         mswnop,     /* t_close: Close terminal at end */
  63.     mswnop,     /* t_kopen: Open keyboard */
  64.     mswnop,     /* t_kclose: close keyboard */
  65.     mswgetc,    /* t_getchar: Get character from keyboard */
  66.         mswputc,    /* t_putchar: Put character to display */
  67.         mswflush,   /* t_flush: Flush output buffers */
  68.         mswmove,    /* t_move: Move the cursor, origin 0 */
  69.         msweeol,    /* t_eeol: Erase to end of line */
  70.         msweeop,    /* t_eeop: Erase to end of page */
  71.     mswnop,     /* t_clrdesk: Clear the page totally */
  72.     mswbeep,    /* t_beep: Sound beep */
  73.     mswrev,     /* t_rev: set reverse video state */
  74.     mswrez,     /* t_rez: change screen resolution */
  75. #if    COLOR
  76.     mswsetfor,  /* t_setfor: set forground color */
  77.     mswsetback, /* t_setback: set background color */
  78. #endif
  79.     mswsleep,   /* t_sleep: wait a while */
  80.     mswnewscr,  /* t_newscr: create new "screen" display */
  81.     mswdelscr,  /* t_delscr: destroy "screen" display */
  82.     mswselscr,  /* t_selscr: select "screen" display for IO */
  83.     mswsizscr,  /* t_sizscr: resize "screen" display */
  84.         mswtopscr   /* t_topscr: bring "screen" to top */
  85. };
  86.  
  87. #define MAXMLHIST   8       /* must be a power of 2 */
  88. #define MLHISTMASK  0x7     /* corresponding bit mask */
  89. static char *MLHistory[MAXMLHIST] = {NULL};
  90.     /* circular history of the last few message line entries */
  91. static int  MLHistOld = 0;  /* index of the oldest message */
  92. static int  MLHistNew = 0;  /* index of the first empty slot */
  93.  
  94. static HWND hIOWnd;         /* current window where I/Os take place */
  95.  
  96. static int  UpdateRow;      /* Row being updated (-1 for no update) */
  97.  
  98. static struct {
  99.     int leftmost;
  100.     int rightmost;      /* -1 indicates the range is empty */
  101. } UpdateCol;                /* Columns to invalidate on UpdateRow */
  102.  
  103. static SCREEN *IOScr;       /* Screen affected by the I/Os */
  104.  
  105. static BOOL RevStatus;      /* Reverse video flag */
  106. #if     COLOR
  107. static int  ForgColor;      /* current selection of foreground and */
  108. static int  BackColor;      /* background colors */
  109. #endif
  110.  
  111. /* PushMLHist:  store the last message line contents in the history */
  112. /* ==========                                                       */
  113.  
  114. static void PASCAL  PushMLHist (void)
  115. {
  116.     char    *ml;
  117.     int     i, e;
  118.  
  119.     for (e = MLSIZE - 1; e >= 0; e--) if (MLBuf[e] != ' ') break;
  120.         /* e = index of the last non-space char */
  121.     if (e < 0) return;
  122.     if ((ml = MLHistory[MLHistNew] = malloc (e + 2)) != NULL) {
  123.         for (i = 0; i <= e; i++) *ml++ = MLBuf[i];
  124.         *ml = '\0';     /* terminate the string */
  125.     MLHistNew = (MLHistNew + 1) & MLHISTMASK;
  126.     if (MLHistOld == MLHistNew) {
  127.         /* the history is full. This old entry needs to be discarded */
  128.         free (MLHistory[MLHistOld]);
  129.         MLHistOld = (MLHistOld + 1) & MLHISTMASK;
  130.     }
  131.     }
  132. } /* PushMLHist */
  133.  
  134. /* MLHistDlgProc:   dialog proc for the Message Line History */
  135. /* =============                                             */
  136.  
  137. int EXPORT FAR PASCAL  MLHistDlgProc (HWND hDlg, UINT wMsg,
  138.                                       UINT wParam, LONG lParam)
  139. {
  140.     switch (wMsg) {
  141.         
  142.     case WM_INITDIALOG:
  143.         {
  144.             char    s[50];
  145.  
  146.             strcpy (s, PROGNAME);
  147.             strcat (s, TEXT330);
  148.             SetWindowText (hDlg, s);
  149.         }
  150.         /*-fill the list box */
  151.         while (MLHistOld != MLHistNew) {
  152.             SendDlgItemMessage (hDlg, ID_HIST, LB_ADDSTRING, 0,
  153.                                 (DWORD)MLHistory[MLHistOld]);
  154.             free (MLHistory[MLHistOld]);
  155.             MLHistOld = (MLHistOld + 1) & MLHISTMASK;
  156.         }
  157.     /*-scroll the last message into view */
  158.         {
  159.             int     i;
  160.  
  161.             i = SendDlgItemMessage (hDlg, ID_HIST, LB_GETCOUNT, 0, 0L);
  162.             SendDlgItemMessage (hDlg, ID_HIST, LB_SETCURSEL, i - 1, 0L);
  163.             SendDlgItemMessage (hDlg, ID_HIST, LB_SETCURSEL, -1, 0L);
  164.         }
  165.     return TRUE;
  166.     
  167.     case WM_COMMAND:
  168.     if (NOTIFICATION_CODE != BN_CLICKED) break;
  169.     if (LOWORD(wParam) == 1) {
  170.         EndDialog (hDlg, 0);
  171.         return TRUE;
  172.     }
  173.     break;
  174.     }
  175.     return FALSE;
  176. } /* MLHistDlgProc */
  177.  
  178. /* mlhistory:   displays the message line history box */
  179. /* =========                                          */
  180.  
  181. /* This function is needed because the message line only shows the last
  182.    message. If a macro fails, it usually generates a slew of errors
  183.    (each beginning by a \n). Eventually, calling this function in the
  184.    core editor loop will pop up a dialog box showing up to MAXMLHIST-1
  185.    past messages */
  186.  
  187. PASCAL mlhistory (void)
  188. {
  189.     FARPROC     ProcInstance;
  190.  
  191.     PushMLHist ();
  192.     mlferase ();
  193.     ProcInstance = MakeProcInstance ((FARPROC)MLHistDlgProc,
  194.                          hEmacsInstance);
  195.     DialogBox (hEmacsInstance, "MLHIST", hFrameWnd, ProcInstance);
  196.     FreeProcInstance (ProcInstance);
  197. } /* mlhistory */
  198.  
  199. static void PASCAL ChangeUpdateRow (int newrow)
  200. /* Set UpdateRow to newrow, invalidating the changed cells in the
  201.    previous update row */
  202. {
  203.     if ((UpdateCol.rightmost >= 0) && (UpdateRow >= 0)) {
  204.         InvalidateCells (hIOWnd, UpdateCol.leftmost, UpdateRow,
  205.                          UpdateCol.rightmost, UpdateRow);
  206.     }
  207.     UpdateRow = newrow;
  208. } /* ChangeUpdateRow */
  209.  
  210. /*****************************************/
  211. /* mswopen: initialize windows interface */
  212. /* =======                               */
  213.  
  214. static int PASCAL mswopen ()
  215. {
  216.     static BOOL FirstTime = TRUE;
  217.  
  218.     if (FirstTime) {
  219.     int     x;
  220.  
  221.     revexist = TRUE;
  222.     eolexist = TRUE;
  223.     strcpy (sres, "MSWIN");     /* $SRES emacs variable */
  224.     MLBuf = (char*)malloc(MLSIZE);
  225.     for (x = 0; x < MLSIZE;) MLBuf[x++] = ' ';
  226.     FirstTime = FALSE;
  227.     }
  228.     UpdateRow = -1;
  229.     UpdateCol.rightmost = -1;
  230.     UpdateCol.leftmost = HUGE; /* empty range */
  231.     return 0;
  232. } /* mswopen */
  233.  
  234. /***************************************************/
  235. /* mswgetc: get character from keyboard (or mouse) */
  236. /* =======                                         */
  237.  
  238. static int PASCAL mswgetc ()
  239. {
  240.     return GetInput ();
  241. } /* mswgetc */
  242.  
  243. /*************************************/
  244. /* mswputc: put character to display */
  245. /* =======                           */
  246.  
  247. static int PASCAL mswputc (c)
  248. int     c;  /* character to write (or 0 for dummy write) */
  249. {
  250.     if (UpdateRow != CurrentRow) {
  251.         ChangeUpdateRow (CurrentRow);
  252.         UpdateCol.rightmost = -1;
  253.         UpdateCol.leftmost = HUGE; /* empty range */
  254.     }
  255.  
  256.     /*-set the colors and reverse status in the display buffer */
  257.     if (hIOWnd != hFrameWnd) {  /* not supported on message line */
  258.     register VIDEO   *vp;
  259.  
  260.     vp = IOScr->s_physical[UpdateRow];
  261.     vp->v_fcolor = ForgColor;
  262.     vp->v_bcolor = BackColor;
  263.     if (RevStatus) vp->v_flag |= VFREV;
  264.     else vp->v_flag &= ~VFREV;
  265.     }
  266.     
  267.     /*-update the cursor's position and the UpdateCol range. Update the
  268.        message line buffer if that's where the fun is */
  269.     if (c != 0) {
  270.     if (CurrentCol < UpdateCol.leftmost) UpdateCol.leftmost = CurrentCol;
  271.     if (CurrentCol > UpdateCol.rightmost) UpdateCol.rightmost = CurrentCol;
  272.     if (hIOWnd == hFrameWnd) {          /* message line */
  273.         if (c == '\b') {
  274.             if (CurrentCol > 0) MLBuf[--CurrentCol] = ' ';
  275.         }
  276.         else {
  277.             if (c == '\n') PushMLHist();
  278.             else {
  279.             MLBuf[CurrentCol] = c;
  280.             if (CurrentCol < MLSIZE - 1) ++CurrentCol;
  281.         }
  282.         } 
  283.     }
  284.     else ++CurrentCol;
  285.     }
  286.     return 0;
  287. } /* mswputc */
  288.  
  289. /**************************************************/
  290. /* mswflush:    update display from output buffer */
  291. /* ========                                       */
  292.  
  293. static int PASCAL mswflush ()
  294. {
  295.     ChangeUpdateRow (-1);
  296.     if (!InternalRequest && (hIOWnd == hFrameWnd)) UpdateWindow (hIOWnd);
  297.     /* note: we do not update screens in real time */
  298.     MoveEmacsCaret (hIOWnd, CurrentCol, CurrentRow);
  299.         /* some caret movement is directly handled by the driver (see
  300.        mswputc) */
  301.     return 0;
  302. } /* mswflush */
  303.  
  304. /****************************/
  305. /* mswmove: move the cursor */
  306. /* =======                  */
  307.  
  308. static int PASCAL mswmove (int newrow, int newcol)
  309. {
  310.     /*-perform IO windows switching depending on the addressed row: if
  311.        beyond the IO screen, the message line is addressed*/
  312.     if (!IOScr || (newrow >= IOScr->s_nrow)) {
  313.         if (hIOWnd != hFrameWnd) {
  314.             ChangeUpdateRow (-1);
  315.             hIOWnd = hFrameWnd;
  316.         }
  317.         CurrentRow = 0;
  318.     }
  319.     else {
  320.         if (hIOWnd != IOScr->s_drvhandle) {
  321.             ChangeUpdateRow (-1);
  322.             hIOWnd = IOScr->s_drvhandle;
  323.         }
  324.         CurrentRow = newrow;
  325.     }
  326.  
  327.     CurrentCol = newcol;
  328.  
  329.     /*-update the caret */
  330.     MoveEmacsCaret (hIOWnd, CurrentCol, CurrentRow);
  331.     return 0;
  332. } /* mswmove */
  333.  
  334. /*********************************/
  335. /* msweeol: erase to end of line */
  336. /* =======                       */
  337.  
  338. static int PASCAL msweeol ()
  339. {
  340.     mswputc (0);    /* ensure change of row is properly handled */
  341.     UpdateCol.leftmost = min(UpdateCol.leftmost,CurrentCol);
  342.     if (hIOWnd == hFrameWnd) {          /* message line */
  343.     int     x;
  344.     
  345.     for (x = CurrentCol; x < MLSIZE;) MLBuf[x++] = ' ';
  346.     UpdateCol.rightmost = MLSIZE - 1;
  347.     }
  348.     else {
  349.     UpdateCol.rightmost = IOScr->s_ncol;
  350.     }
  351.     mswflush ();
  352.     return 0;
  353. } /* msweeol */
  354.  
  355. /*********************************/
  356. /* msweeop: erase to end of page */
  357. /* =======                       */
  358.  
  359. static int PASCAL msweeop ()
  360. {
  361.     if (hIOWnd == hFrameWnd) {          /* message line */
  362.     msweeol ();     /* only one line here */
  363.     return 0;
  364.     }
  365.     mswputc (0);    /* ensure change of row is properly handled */
  366.     UpdateCol.leftmost = min(UpdateCol.leftmost,CurrentCol);
  367.     InvalidateCells (hIOWnd, UpdateCol.leftmost, UpdateRow,
  368.              IOScr->s_ncol, UpdateRow);
  369.     if (CurrentRow + 1 < IOScr->s_nrow) {
  370.     register int    r;
  371.     register VIDEO  *vp;
  372.  
  373.     /*-propagate the colors and reverse status */
  374.     for (r = CurrentRow + 1; r < IOScr->s_nrow; r++) {
  375.         vp = IOScr->s_physical[r];
  376.         vp->v_fcolor = ForgColor;
  377.         vp->v_bcolor = BackColor;
  378.         if (RevStatus) vp->v_flag |= VFREV;
  379.         else vp->v_flag &= ~VFREV;
  380.     }
  381.     /*-flag the area for repaint */
  382.     InvalidateCells (hIOWnd, 0, CurrentRow + 1,
  383.              IOScr->s_ncol, IOScr->s_nrow);
  384.     }
  385.     mswflush ();
  386.     return 0;
  387. } /* msweeop */
  388.  
  389. /*************************/
  390. /* mswbeep: sound a beep */
  391. /* =======               */
  392.  
  393. static int PASCAL mswbeep ()
  394. {
  395.     MessageBeep (0);
  396.     return 0;
  397. } /* mswbeep */
  398.  
  399. /************************************/
  400. /* mswrev:  set reverse video state */
  401. /* ======                           */
  402.  
  403. static int PASCAL mswrev (state)
  404. int     state;      /* TRUE = reverse, FALSE = normal */
  405. {
  406.     RevStatus = state;
  407.     return 0;
  408. } /* mswrev */
  409.  
  410. /************************************/
  411. /* mswrez:  change "resolution"     */
  412. /* ======                           */
  413.  
  414. static int PASCAL mswrez (res)
  415. char    *res;
  416. {
  417.     return TRUE;   /* $SRES is read-only in MSWIN, but returning an
  418.               error may break existing macros */
  419. } /* mswrez */
  420.  
  421. #if COLOR
  422. /* mswsetfor:   set foreground color */
  423. /* =========                         */
  424.  
  425. static int  PASCAL mswsetfor (color)
  426. int     color;
  427. {
  428.     ForgColor = color;
  429.     return 0;
  430. } /* mswsetfor */
  431.  
  432. /* mswsetback:  set background color */
  433. /* ==========                        */
  434.  
  435. static int  PASCAL mswsetback (color)
  436. int     color;
  437. {
  438.     BackColor = color;
  439.     return 0;
  440. } /* mswsetback */
  441. #endif
  442.  
  443. /* mswsleep:    wait a specified time (in ms) in an unobtrusive way */
  444. /* ========                                                         */
  445.  
  446. static int PASCAL   mswsleep (int t)
  447. {
  448.     return TakeANap (t);
  449. } /* mswsleep */
  450.  
  451. /* mswnewscr:   create new MDI window for new screen */
  452. /* =========                                         */
  453.  
  454. static int PASCAL mswnewscr (SCREEN *sp)
  455. /* called by screen.c after the screen structure has been allocated. The
  456.    size of the screen will be determined by the window's size. returns
  457.    TRUE if successful. */
  458. {
  459.     MDICREATESTRUCT cs;
  460.     BOOL    Maximized;
  461.  
  462. #if WINDOW_MSWIN32
  463.     Maximized = (GetWindowLong((HWND)SendMessage (hMDIClientWnd,
  464.                                                   WM_MDIGETACTIVE,
  465.                                                   0, 0L),
  466.                                 GWL_STYLE) & WS_MAXIMIZE);
  467. #else
  468.     Maximized = HIWORD(SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L));
  469. #endif
  470.     if (Maximized) {
  471.         restorescreen (FALSE, 0);   /* de-maximize previous one */
  472.     }
  473.     if (first_screen == NULL) Maximized = TRUE;
  474.     cs.szClass = ScreenClassName;
  475.     cs.szTitle = sp->s_screen_name;
  476.     cs.hOwner = hEmacsInstance;
  477.     cs.x = CW_USEDEFAULT;
  478.     cs.y = CW_USEDEFAULT;
  479.     cs.cx = CW_USEDEFAULT;
  480.     cs.cy = CW_USEDEFAULT;
  481.     if (Maximized) cs.style = WS_MAXIMIZE;
  482.     else cs.style = 0;
  483.     cs.style |= WS_HSCROLL | WS_VSCROLL;
  484.     cs.lParam = (DWORD)sp;
  485.     sp->s_virtual = NULL;     /* not NULL will testify of success */
  486.     InternalRequest = TRUE;
  487.     SendMessage (hMDIClientWnd, WM_MDICREATE, 0, (DWORD)(LPSTR)&cs);
  488.     if (sp->s_virtual) {
  489.         if (hFrameWnd == GetActiveWindow ()) SetFocus (sp->s_drvhandle);
  490.     }
  491.     InternalRequest = FALSE;
  492.     if (!sp->s_virtual) {
  493.         mswdelscr (sp);     /* failed, cleanup! */
  494.         return FALSE;
  495.     }
  496.     return TRUE;
  497. } /* mswnewscr */
  498.  
  499. /* mswdelscr:   destroys an MDI window for a disappearing screen */
  500. /* =========                                                     */
  501.  
  502. static int PASCAL mswdelscr (SCREEN *sp)
  503. /* called by screen.c before the screen structure is deallocated */
  504. {
  505.     if (sp->s_drvhandle == hIOWnd) mswflush ();
  506.     if (sp == IOScr) mswselscr (first_screen);
  507.         /* hopefully, at this time, sp!=first_screen */ 
  508.     SendMessage (hMDIClientWnd, WM_MDIDESTROY, (UINT)sp->s_drvhandle, 0L);
  509. } /* mswdelscr */
  510.  
  511. /* mswselscr:   select a window/screen combination for the next IOs */
  512. /* =========                                                        */
  513.  
  514. static int PASCAL mswselscr (SCREEN *sp)
  515. {
  516.     hIOWnd = sp->s_drvhandle;
  517.     IOScr = sp;
  518. } /* mswselscr */
  519.  
  520. /* mswsizscr:   resize an MDI window to fit the associated screen */
  521. /* =========                                                      */
  522.  
  523. static int PASCAL mswsizscr (SCREEN *sp)
  524. /* called by Emacs when the screen's dimensions have been changed. A resize
  525.    through the MS-Windows interface is handled by the ReSize function in
  526.    mswdisp.c */
  527. {
  528.     HWND    hScrWnd;
  529.     BOOL    Maximized;
  530.     int     RetryCount = -1;    /* prevents infinite loop if frame
  531.                    window can't be resized properly */
  532.     BOOL    FrameIconic;
  533. #if !WIN30SDK
  534.     WINDOWPLACEMENT WindowPlacement;
  535. #endif
  536.  
  537.     if (InternalRequest) return;
  538.     InternalRequest = TRUE;
  539.     hScrWnd = sp->s_drvhandle;
  540.  
  541.     {   /*-If this is iconized, we have to restore it first to be
  542.        allowed to change its size. If it is the active MDI child and
  543.        is maximized, we will actually resize the frame window so, if
  544.        the later is maximized, we restore it first. */
  545.        
  546. #if WINDOW_MSWIN32
  547.     HWND   hActiveScr;
  548.  
  549.     hActiveScr = (HWND)SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L);
  550.         Maximized = (hScrWnd == hActiveScr) &&
  551.                     (GetWindowLong(hScrWnd, GWL_STYLE) & WS_MAXIMIZE);
  552. #else
  553.     DWORD   ActiveScr;
  554.  
  555.     ActiveScr = SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L);
  556.         Maximized = (hScrWnd == LOWORD(ActiveScr)) && HIWORD(ActiveScr);
  557. #endif
  558.     if (IsIconic (hScrWnd)) {
  559.         SendMessage (hMDIClientWnd, WM_MDIRESTORE, (UINT)hScrWnd, 0L);
  560.     }
  561.         if (Maximized && IsZoomed (hFrameWnd)) {
  562.             ShowWindow (hFrameWnd, SW_RESTORE);
  563.         }
  564.     }
  565.     FrameIconic = IsIconic (hFrameWnd);
  566.     do {/*-Now, proceed with resizing... */
  567.     int     Delta;
  568.     RECT    TargetRect, BoundingRect;   /* in MDIClient coordinates */
  569.     RECT    OldClientRect;
  570.     POINT   ClientSize;
  571.  
  572.     GetClientRect (hScrWnd, &OldClientRect);
  573.     MinimumClientSize (hScrWnd, sp->s_ncol, sp->s_nrow,
  574.                            &ClientSize.x, &ClientSize.y);
  575.     if (Maximized) {
  576.         if (((OldClientRect.bottom == ClientSize.y)
  577.              && (OldClientRect.right == ClientSize.x))
  578.                 || (RetryCount > 0)) break; /* exit the resize loop */
  579.         ++RetryCount;
  580.         BoundingRect.left = BoundingRect.top = 0;
  581.         BoundingRect.right = GetSystemMetrics (SM_CXSCREEN);
  582.         BoundingRect.bottom = GetSystemMetrics (SM_CYSCREEN);
  583. #if WIN30SDK
  584.             {
  585. #else
  586.             if (FrameIconic && Win31API) {
  587.                 GetWindowPlacement (hFrameWnd, &WindowPlacement);
  588.                 TargetRect = WindowPlacement.rcNormalPosition;
  589.             }
  590.             else {
  591. #endif
  592.             GetWindowRect (hFrameWnd, &TargetRect);
  593.         }
  594.     }
  595.     else {
  596.         GetClientRect (hMDIClientWnd, &BoundingRect);
  597.         GetWindowRect (hScrWnd, &TargetRect);
  598.         ScreenToClient (hMDIClientWnd, (LPPOINT)&TargetRect.right);
  599.         ScreenToClient (hMDIClientWnd, (LPPOINT)&TargetRect.left);
  600.     }
  601.  
  602.         /*-process change of width: we move the right edge. If it would
  603.        go off bounds, we move the left edge back to compensate, but
  604.        never below 0 */
  605.     Delta = ClientSize.x - OldClientRect.right;
  606.     if ((TargetRect.right + Delta) > BoundingRect.right) {
  607.         TargetRect.left += (BoundingRect.right - TargetRect.right)
  608.                                - Delta;
  609.         TargetRect.right = BoundingRect.right;
  610.         if (TargetRect.left < 0) {
  611.         TargetRect.right -= TargetRect.left;
  612.         TargetRect.left = 0;
  613.         }
  614.     }
  615.     else TargetRect.right += Delta;
  616.  
  617.     /*-process change of height: we move the bottom edge. If it
  618.        would go off screen, we move the top edge up to compensate,
  619.        but never beyond 0 */
  620.     Delta = ClientSize.y - OldClientRect.bottom;
  621.     if ((TargetRect.bottom + Delta) > BoundingRect.bottom) {
  622.         TargetRect.top += (BoundingRect.bottom - TargetRect.bottom)
  623.                               - Delta;
  624.         TargetRect.bottom = BoundingRect.bottom;
  625.         if (TargetRect.top < 0) {
  626.         TargetRect.bottom -= TargetRect.top;
  627.         TargetRect.top = 0;
  628.         }
  629.     }
  630.     else TargetRect.bottom += Delta;
  631.  
  632. #if WIN30SDK
  633.         {
  634. #else
  635.         if (Maximized && FrameIconic && Win31API) {
  636.             WindowPlacement.rcNormalPosition = TargetRect;
  637.             SetWindowPlacement (hFrameWnd, &WindowPlacement);
  638.         }
  639.         else {
  640. #endif
  641.         SetWindowPos (Maximized ? hFrameWnd : hScrWnd, 0,
  642.                         TargetRect.left, TargetRect.top,
  643.                     TargetRect.right - TargetRect.left,
  644.                     TargetRect.bottom - TargetRect.top,
  645.                         SWP_DRAWFRAME | SWP_NOZORDER);
  646.         }
  647.     } while (Maximized);    /* if Maximized, we loop once in case a
  648.                    change of menu bar height has prevented
  649.                    us from getting the expected client size
  650.                    */
  651.     InternalRequest = FALSE;
  652. } /* mswsizscr */
  653.  
  654. /* mswtopscr:   bring a screen's window to top. */
  655. /* =========                                    */
  656.  
  657. static int PASCAL mswtopscr (SCREEN *sp)
  658.  
  659. /* called by screen.c when selecting a screen for current */
  660. {
  661.     if (!InternalRequest) {
  662.     InternalRequest = TRUE;
  663.     SendMessage (hMDIClientWnd, WM_MDIACTIVATE,
  664.              (UINT)sp->s_drvhandle, 0L);
  665. #if WINDOW_MSWIN32
  666.     if (GetWindowLong(sp->s_drvhandle, GWL_STYLE) & WS_MAXIMIZE) {
  667. #else
  668.     if (HIWORD(SendMessage (hMDIClientWnd, WM_MDIGETACTIVE, 0, 0L))) {
  669. #endif
  670.         /* we have a maximized screen. Since we activated it under
  671.            InternalRequest, the new size has not yet been processed
  672.            by emacs, so we have to fix that */
  673.         newwidth (TRUE, DisplayableColumns (sp->s_drvhandle, 0, &EmacsCM));
  674.         newsize (TRUE, DisplayableRows (sp->s_drvhandle, 0, &EmacsCM));
  675.     }
  676.     InternalRequest = FALSE;
  677.     }
  678. } /* mswtopscr */
  679.  
  680. /*************************/
  681. /* mswnop:  No Operation */
  682. /* ======                */
  683.  
  684. static int PASCAL mswnop ()
  685. {
  686.     return 0;
  687. }
  688.